//
//  VKVoucherChildCell.m
//  V-Learn
//
//  Created by liubo on 2019/1/10.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "VKMeWeiOrderCell.h"

@implementation VKMeWeiOrderCell{
    UIImageView *_iconView;
    UILabel *_titleLabel;
    UILabel *_subLabel;
    UILabel *_timeLabel;
    UILabel *_moneyLabel;
}

+ (instancetype)cellWithTableView:(UITableView *)tableView{
    VKMeWeiOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:@"VKMeWeiOrderCell"];
    if (cell == nil) {
        cell = [[VKMeWeiOrderCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"VKMeWeiOrderCell"];
    }
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    return cell;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // 点击cell的时候不要变色
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor cz_colorWithRed:244 green:244 blue:244];
        // 布局子控件
        [self autoLayout];
    }
    return self;
}

-(void)setModel:(VKMeOrderModel *)model{
    _model = model;
    _titleLabel.text = model.courseName;
    _subLabel.text = model.courseTitle;
    _timeLabel.text = model.payTime;
    if ([model.courseOutputDTO.courseImage isEqual:[NSNull null]]||model.courseOutputDTO.courseImage==nil) {
        _iconView.image = [UIImage imageNamed:@"wk_list_bgimg"];
    }else{
        [_iconView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",Public_URL,model.courseOutputDTO.courseImage]] placeholderImage:[UIImage imageNamed:@"wk_list_bgimg"]];
    }
    [self downCountAttributedleftString:@"合计:" withCenterString:@"¥" withRightString:model.coursePrice withLabel:_moneyLabel];

}

- (void)autoLayout{
    // 底部视图
    UIView *rightView = [[UIView alloc] init];
    rightView.backgroundColor = [UIColor whiteColor];
    rightView.layer.masksToBounds = YES;
    rightView.layer.cornerRadius = 4;
    [self.contentView addSubview:rightView];
    [rightView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@10);
        make.left.equalTo(@(10));
        make.height.equalTo(@165);
        make.right.equalTo(@(-10));
    }];
    
    // 图片
    UIImageView *iconView = [[UIImageView alloc] init];
    [rightView addSubview:iconView];
    _iconView = iconView;
    iconView.layer.masksToBounds = YES;
    iconView.layer.cornerRadius = 6;
//    iconView.image = [UIImage imageNamed:@"girl"];
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@180);
        make.left.mas_equalTo(@10);
        make.height.equalTo(@120);
        make.top.mas_equalTo(rightView).offset(10);
    }];
    
    UILabel *titleLabel = [[UILabel alloc] init];
    [rightView addSubview:titleLabel];
    _titleLabel = titleLabel;
//    titleLabel.text = @"主题课程二级";
    titleLabel.font = [UIFont systemFontOfSize:16];
    titleLabel.textColor = [UIColor cz_colorWithRed:40 green:40 blue:40];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(iconView);
        make.left.mas_equalTo(iconView.mas_right).offset(10);
        make.right.mas_equalTo(rightView).offset(-6);
    }];
    
    UILabel *subLabel = [[UILabel alloc] init];
    [rightView addSubview:subLabel];
    _subLabel = subLabel;
    subLabel.numberOfLines = 0;
//    subLabel.text = @"主题课程二级主题课程二级主题课程二级主题课程二级主题课程二级";
    subLabel.font = [UIFont systemFontOfSize:14];
    subLabel.textColor = [UIColor cz_colorWithRed:115 green:115 blue:115];
    [subLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLabel.mas_bottom).offset(8);
        make.left.mas_equalTo(titleLabel);
        make.right.mas_equalTo(rightView).offset(-10);
    }];
    
    UILabel *timeLabel = [[UILabel alloc] init];
    [rightView addSubview:timeLabel];
    _timeLabel = timeLabel;
    timeLabel.numberOfLines = 0;
//    timeLabel.text = @"2018-08-01";
    timeLabel.font = [UIFont systemFontOfSize:14];
    timeLabel.textColor = [UIColor cz_colorWithRed:152 green:152 blue:152];
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(iconView.mas_bottom).offset(10);
        make.left.mas_equalTo(iconView);
    }];
    
//    UIButton *payBtn = [[UIButton alloc] init];
//    [rightView addSubview:payBtn];
//    payBtn.titleLabel.font = [UIFont systemFontOfSize:13];
//    [payBtn setTitleColor:[UIColor cz_colorWithRed:253 green:79 blue:83] forState:UIControlStateNormal];
//    payBtn.layer.cornerRadius = 20 / 2.0;
//    payBtn.layer.borderColor = [UIColor cz_colorWithRed:253 green:79 blue:83].CGColor;
//    payBtn.layer.borderWidth = 1;
//    [payBtn setTitle:@"支付" forState:UIControlStateNormal];
//    [payBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.mas_equalTo(rightView).offset(-10);
//        make.centerY.equalTo(timeLabel);
//        make.width.equalTo(@55);
//        make.height.equalTo(@20);
//    }];
    
    UILabel *moneyLabel = [[UILabel alloc] init];
    [rightView addSubview:moneyLabel];
    _moneyLabel = moneyLabel;
//    moneyLabel.text = @"合计:¥699";
    moneyLabel.font = [UIFont systemFontOfSize:14];
//    moneyLabel.textColor = [UIColor cz_colorWithRed:152 green:152 blue:152];
    [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(timeLabel);
        make.right.mas_equalTo(-10);
    }];
//    [self downCountAttributedleftString:@"合计:" withCenterString:@"¥" withRightString:@"699" withLabel:moneyLabel];
}

- (void)downCountAttributedleftString:(NSString *)leftString withCenterString:(NSString *)centerString withRightString:(NSString *)rightString withLabel:(UILabel *)contentLabel {
    
    // 左边的文字颜色
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc]initWithString:leftString attributes:@{NSForegroundColorAttributeName:[UIColor cz_colorWithRed:152 green:152 blue:152],NSFontAttributeName:[UIFont systemFontOfSize:14.0]}];
    
    // 中间的文字
    NSMutableAttributedString *centerS = [[NSMutableAttributedString alloc]initWithString:centerString attributes:@{NSForegroundColorAttributeName:[UIColor cz_colorWithRed:253 green:79 blue:83],NSFontAttributeName:[UIFont systemFontOfSize:14.0]}];
    [string insertAttributedString:centerS atIndex:leftString.length];
    
    // 右边的文字颜色
    NSMutableAttributedString *rightS = [[NSMutableAttributedString alloc]initWithString:rightString attributes:@{NSForegroundColorAttributeName:[UIColor cz_colorWithRed:253 green:79 blue:83],NSFontAttributeName:[UIFont systemFontOfSize:19.0]}];
    [string insertAttributedString:rightS atIndex:string.length];
    contentLabel.attributedText = string;
}
@end

